class Solution {
public:
    vector<vector<int>> ret;
    vector<int> nums;
    void PreOrder(TreeNode* root, int target)
    {
        if (root == nullptr)
            return;
        nums.push_back(root->val);
        target -= root->val;
        if (root->left == nullptr && root->right == nullptr && target == 0)
            ret.push_back(nums);
        PreOrder(root->left, target);
        PreOrder(root->right, target);
        nums.pop_back();
    }
    vector<vector<int>> pathSum(TreeNode* root, int target) {
        PreOrder(root, target);
        return ret;
    }
};